#include<iostream>
using namespace std;
class _clock {
private:
	int hour;
	int minute;
	int second;
public:
	_clock(int h,int m,int s):hour(h),minute(m),second(s){}
	friend void operator ++(_clock& a) {
		a.second++;
		if (a.second > 59) {
			a.minute++;
			a.second -= 60;
		}
		if (a.minute > 59) {
			a.hour++;
			a.minute -= 60;
		}
		if (a.hour > 11) {
			a.hour -= 12;
		}
	}
	friend void operator --(_clock& a,int) {
		a.second--;
		if (a.second < 0) {
			a.minute--;
			a.second += 60;
		}
		if (a.minute < 0) {
			a.hour--;
			a.minute += 60;
		}
		if (a.hour < 0) {
			a.hour += 12;
		}
	}
	void show() {
		cout << hour << ':' << minute << ':' << second << endl;
	}
};
int main()
{
	int h, m, s;
	cin >> h >> m >> s;
	_clock a(h, m, s);
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		int n;
		cin >> n;
		if (n > 0) {
			while (n) {
				++a;
				n--;
			}
		}
		else {
			n = -n;
			while (n) {
				a--;
				n--;
			}
		}
		a.show();
	}
	return 0;
}